<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>登录</title>

        <link rel="stylesheet" href="./layui/css/layui.css" />
        <style>
            body{
                background-color: #ccc;
            }
            .card{
                width: 500px;
                height:300px;
                margin:auto;
            }
        </style>
    </head>
    <body>
        <div class="layui-card card">
            <div class="layui-card-header">登录</div>
            <div class="layui-card-body">
                <form class="layui-form" lay-filter="loginForm" action="">
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户名</label>
                        <div class="layui-input-block">
                            <input
                                type="text"
                                name="username"
                                required
                                lay-verify="required"
                                placeholder="请输入用户名"
                                autocomplete="off"
                                class="layui-input"
                            />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">密码框</label>
                        <div class="layui-input-block">
                            <input
                                type="password"
                                name="pwd"
                                required
                                lay-verify="required"
                                placeholder="请输入密码"
                                autocomplete="off"
                                class="layui-input"
                            />
                        </div>
                    </div>
                 

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button
                                class="layui-btn"
                                lay-submit
                                lay-filter="loginSubmit"
                            >
                                立即提交
                            </button>
                            <button
                                type="reset"
                                class="layui-btn layui-btn-primary"
                            >
                                重置
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <script src="./layui/layui.js"></script>
        <script>
            layui.define(function(){
                let {form,$,layer} = layui;
               
                form.on("submit(loginSubmit)",function(data){
                    $.ajax({
                        type:"post",
                        url:"/users/login",
                        data:data.field,
                        success(res){
                            if(res.status == 1){
                                layer.alert("登录成功",function(){
                                    location.href = "manage.html";
                                });
                            }else{
                                layer.alert("登录失败");
                            }
                           
                        }
                    });
                    return false;
                });
               
            });
        </script>
    </body>
</html>
